# -*- coding:utf-8 -*-

# 1. 冒泡排序
"""
lis = [56,12,1,8,354,10,100,34,56,7,23,456,234,-58]

def sortport():
    for i in range(len(lis)-1):
        for j in range(len(lis)-1-i):
            if lis[j] > lis[j+1]:
                lis[j],lis[j+1] = lis[j+1],lis[j]
    return lis

a = sortport()
print(a)

# 2. 计算x的n次方的方法
def power(x,n):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s

b = power(5,7)
print(b)

# 3. 计算a*a + b*b + c*c + ...
def calc(*numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum

c = calc(10,20)
print(c)
"""

#  4. 计算阶乘 n!
"""
def fac():
    num = int(input("请输入一个数字:"))
    factorial = 1

    # 查看数字是负数,0或正数
    if num < 0:
        print("抱歉,负数没有阶乘")
    elif num == 0:
        print("0 的阶乘为1")
    else:
        for i in range(1,num + 1):
            factorial = factorial * i
        print("%d的阶乘为%d" % (num,factorial))

fac()


def factorial(n):
    result = n
    for i in range(1,n):
        result *= i 
    return result

print(factorial(50))

def fact(n):
    if n == 1:
        return 1
    return n * fact(n - 1)
print('===============')
print(fact(30))
"""

"""
# 5. 列出当前目录下的所有文件和目录名
import os
print([d for d in os.listdir('.')])

# 6. 把一个list中所有的字符串变成小写.
L = ['THIS','IS','A','VSCODEIDE','SOFTWARE']
print([s.lower() for s in L])



# 7. 输出某个路径下的所有文件和文件夹路径.
def print_dir():
    filepath = input("请输入一个路径:")
    if filepath == "":
        print("请输入正确的路径:")
    else:
        # 获取目录中的文件及子目录列表.
        for i in os.listdir(filepath):

            # 把路径组合起来.
            print(os.path.join(filepath,i)) 

print(print_dir())
# 输出报错,输入路径,如何不报错?
"""

# 8. 输出某个路径及其子目录下所有以.html为后缀的文件.
"""
import os
def print_dir(filepath):
    for i in os.listdir(filepath):
        path = os.path.join(filepath,i)
        if os.path.isdir(path):
            print_dir(path)
        if path.endswith(".html"):
            print(path)

filepath = "/home/liyuanjie/project/py/pyspider/html"
print_dir(filepath)


# 10 把原字典的键值对颠倒并产生新的字典.
dict1 = {"H":'h',"D":'d',"E":'e'}
dict2 = {y:x for x,y in dict1.items()}
print(dict2)

# 11 打印九九乘法表
for i in range(1,10):
    for j in range(1,i+1):
        # print('%d x %d = %d'%(i,j,i*j),end=' ')
        print('{}*{}={}\t'.format(j,i,i*j),end='')
    print()
# 指定end参数的值,取消在末尾输出回车符,实现不换行.
"""


# 12. 替换列表中所有的3为3a
num = ["harden","lampard",3,34,45,56,76,87,78,45,3,3,3,87686,98,76]
print(num.count(3))
print(num.index(3))

# 获取3出现的次数
for i in range(num.count(3)):
    # 获取首次3出现的坐标.
    ele_index = num.index(3)
    num[ele_index] = "3a"  #修改3为3a
    print(num)




